package com.lijianan.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lijianan.entity.MultimediaEquipment;
import com.lijianan.mapper.MultimediaEquipmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MultimediaEquipmentServiceImpl implements MultimediaEquipmentService {

    @Autowired
    private MultimediaEquipmentMapper multimediaEquipmentMapper;

    @Override
    public boolean addMultimediaEquipment(String name) {
        if (selectByName(name) != null) {
            System.out.println("已经存在该设备！");
            return false;
        }
        MultimediaEquipment multimediaEquipment = new MultimediaEquipment();
        multimediaEquipment.setName(name);
        return multimediaEquipmentMapper.insert(multimediaEquipment) != 0;
    }

    @Override
    public MultimediaEquipment selectByEquipmentId(Integer equipment_id) {
        return multimediaEquipmentMapper.selectById(equipment_id);
    }

    @Override
    public MultimediaEquipment selectByName(String name) {
        QueryWrapper<MultimediaEquipment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        return multimediaEquipmentMapper.selectOne(queryWrapper);
    }

    @Override
    public List<MultimediaEquipment> selectAll() {
        return multimediaEquipmentMapper.selectList(null);
    }

    @Override
    public boolean deleteMultimediaEquipment(Integer equipment_id) {
        return multimediaEquipmentMapper.deleteById(equipment_id) != 0;
    }
}
